package org.ma1.cripto.aes.comun;

public class Palabra implements Cloneable{

	private byte[] word = null;
	public Palabra(){
		word = new byte[4];
	}
	
	public Palabra(byte b1 ,byte b2,byte b3,byte b4)
	{
		word[0]=b1;word[1]=b2;word[2]=b3;word[3]=b4;
	}

	public byte[] getWord() {
		return word;
	}

	public void setWord(byte[] word) {
		this.word = word;
	}
	public int size(){
		return getWord().length;
	}
	
	public byte getByte(int i){
		return this.word[i];
	}
	public void setByte(int i, byte b){
		this.word[i]=b;
	}
	
	
	public Palabra xor(Palabra p2){
		Palabra palabraRet = this;
		for(int i=0; i<4; i++){
			palabraRet.setByte(i,((byte)(this.getByte(i) ^  p2.getByte(i))));
		}
			
		return palabraRet;
	}
	
	public String toString(){
		String ret = "";
		int cont = 0;
		while (cont < this.size()){
			ret += " " + this.getWord()[cont];
			cont++;
		}
		return ret;
	}
	
	public Object clone(){
        Palabra obj=null;
        try{
            obj=(Palabra)super.clone();
            obj.setByte(0,this.getByte(0));
            obj.setByte(1,this.getByte(1));
            obj.setByte(2,this.getByte(2));
            obj.setByte(3,this.getByte(3));
        }catch(CloneNotSupportedException ex){
            System.out.println(" no se puede duplicar");
        }
        return obj;
	}
}
